package com.chenyaowei.web.controller.order;

import com.chenyaowei.common.annotation.RepeatSubmit;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.order.request.OrderSubmitRequest;
import com.chenyaowei.order.service.ICywOrderWebService;
import com.chenyaowei.order.vo.OrderConfirmVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/web/order")
public class CywOrderWebController extends BaseController {

    @Autowired
    private ICywOrderWebService orderWebService;

    /**
     * 确认订单
     */
    @RepeatSubmit
    @GetMapping("/confirm")
    public AjaxResult confirmOrder(@RequestParam(value = "skuId", required = false) Long skuId,
                                   @RequestParam(value = "count", required = false) Integer count){
        OrderConfirmVO confirmVO = orderWebService.confirmOrder(skuId, count);
        return success(confirmVO);
    }

    /**
     * 提交订单
     */
    @RepeatSubmit
    @PostMapping("/submit")
    public AjaxResult submitOrder(@Validated @RequestBody OrderSubmitRequest orderSubmitRequest){
        return orderWebService.submitOrder(orderSubmitRequest);
    }


}
